<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="../../../css/personimfcss/cmapplied.css">
    <script type="text/javascript"
            src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
    <script th:inline="javascript">
        var userid = [[${userid}]];
        var page=1;
        var page1=(page-1)*12
        var count;
        //显示组织管理员收到的信息
        $(function() {
            $.ajax({
                url: 'getjoinname.do?userid='+userid+'&page='+page1,
                success: function (data) {//data服务器返回的数据
                    if (data.length != 0) {
                        if (data[0].role1 == "组织管理员") {
                            var n = data[0].joinimf
                            count = parseInt((n + 12 - 1) / 12)
                            zong = $("<p>共" + count + "页 合计" + n + "条数据</p>")
                            gid = data[0].gid
                            $("#shu").append(zong)
                            $.each(data, function (index, grouppeople) {
                                m = $("<tr><td id=\'b\'>" + grouppeople.stunumber + " " + grouppeople.realname + "请求加入组织</td>" +
                                    "<td id=\'b1\'><a href=\"javascript:void(0)\" onclick=\'commit(" + grouppeople.muserid + "," + grouppeople.cuserid + "," + gid + "," + page1 + ")\'>同意</a>" +
                                    "<a href=\"javascript:void(0)\" id=\"no\" onclick=\'nocommit(" + grouppeople.muserid + "," + grouppeople.cuserid + "," + page1 + ")\'>不同意</a></td></tr>")
                                $("#massage").append(m);
                            })
                        }
                        else {
                                var n = data[0].joinimf
                                count = parseInt((n + 12 - 1) / 12)
                                zong = $("<p>共" + count + "页 合计" + n + "条数据</p>")
                                gid = data[0].gid
                                $("#shu").append(zong)
                                $.each(data, function (index, grouppeople) {
                                    m = $("<tr><td id=\'b\'>" + grouppeople.gname + grouppeople.decide + "你加入组织</td>" +
                                        "<td id=\'b2\'><a href=\"javascript:void(0)\" onclick=\'commit1(" + grouppeople.muserid + "," + grouppeople.cuserid + "," + page1 + ")\'>收到</a>" +
                                        "</td></tr>")
                                    $("#massage").append(m);
                                })
                        }
                    }
                    else {
                        count = 0;
                        zong = $("<p>共0页 合计0条数据</p>")
                        $("#shu").append(zong)
                        m = $("<tr><td colspan=\"2\" id=\'b\'>还没有收到消息</td></tr>")
                        $("#massage").append(m);
                    }
                }
            })
            $("#page1").css("background-color","yellow")

        })
        //同意
        function commit(muserid,cuserid,gid,page) {
            $.ajax({
                url: 'updatames.do?muserid='+muserid+'&cuserid='+cuserid+'&gid='+gid+'&page='+page,
                success: function (data) {//data服务器返回的数据
                    $("#massage").empty();
                    $("#shu").empty();
                    if (data.length != 0) {
                        var n = data[0].joinimf
                        count = parseInt((n + 12 - 1) / 12)
                        zong = $("<p>共" + count + "页 合计" + n + "条数据</p>")
                        gid = data[0].gid
                        $("#shu").append(zong)
                        $.each(data, function (index, grouppeople) {
                            m = $("<tr><td id=\'b\'>" +grouppeople.stunumber+" "+grouppeople.realname + "请求加入组织</td>" +
                                "<td id=\'b1\'><a href=\"javascript:void(0)\" onclick=\'commit(" + grouppeople.muserid + "," + grouppeople.cuserid + "," + gid + "," + page1 + ")\'>同意</a>" +
                                "<a href=\"javascript:void(0)\" id=\"no\" onclick=\'nocommit(" + grouppeople.muserid + "," + grouppeople.cuserid + "," + page1 + ")\'>不同意</a></td></tr>")
                            $("#massage").append(m);
                        })

                    }
                    else {
                        zong = $("<p>共0页 合计0条数据</p>")
                        $("#shu").append(zong)
                        m=$("<tr><td colspan=\"2\" id=\'b\'>还没有收到他人请求加入组织的消息</td><td></td></tr>")
                        $("#massage").append(m);
                    }
                }
            })
        }
        //不同意
        function nocommit(muserid,cuserid,page) {
            $.ajax({
                url: 'delectmse.do?muserid='+muserid+'&cuserid='+cuserid+'&page='+page,
                success: function (data) {//data服务器返回的数据
                    $("#massage").empty();
                    $("#shu").empty();
                    if (data.length != 0) {
                        var n = data[0].joinimf
                        count = parseInt((n + 12 - 1) / 12)
                        zong = $("<p>共" + count + "页 合计" + n + "条数据</p>")
                        gid = data[0].gid
                        $("#shu").append(zong)
                        $.each(data, function (index, grouppeople) {
                            m = $("<tr><td id=\'b\'>" + grouppeople.stunumber+" "+grouppeople.realname + "请求加入组织</td>" +
                                "<td id=\'b1\'><a href=\"javascript:void(0)\" onclick=\'commit(" + grouppeople.muserid + "," + grouppeople.cuserid + "," + gid + "," + page1 + ")\'>同意</a>" +
                                "<a href=\"javascript:void(0)\" id=\"no\" onclick=\'nocommit(" + grouppeople.muserid + "," + grouppeople.cuserid + "," + page1 + ")\'>不同意</a></td></tr>")
                            $("#massage").append(m);
                        })

                    }
                    else {
                        zong = $("<p>共0页 合计0条数据</p>")
                        $("#shu").append(zong)
                        m=$("<tr><td colspan=\"2\" id=\'b\'>还没有收到他人请求加入组织的消息</td><td></td></tr>")
                        $("#massage").append(m);
                    }
                }
            })

        }
        function commit1(muserid,cuserid,page) {
            $.ajax({
                url: 'cmdelectmse.do?muserid='+muserid+'&cuserid='+cuserid+'&page='+page,
                success: function (data) {//data服务器返回的数据
                    $("#massage").empty();
                    $("#shu").empty();
                    if (data.length != 0) {
                        var n = data[0].joinimf
                        count = parseInt((n + 12 - 1) / 12)
                        zong = $("<p>共" + count + "页 合计" + n + "条数据</p>")
                        gid = data[0].gid
                        $("#shu").append(zong)
                        $.each(data, function (index, grouppeople) {
                            m = $("<tr><td id=\'b\'>" + grouppeople.gname + grouppeople.decide + "你加入组织</td>" +
                                "<td id=\'b2\'><a href=\"javascript:void(0)\" onclick=\'commit1(" + grouppeople.muserid + "," + grouppeople.cuserid + "," + page1 + ")\'>收到</a>" +
                                "</td></tr>")
                            $("#massage").append(m);
                        })

                    }
                    else {
                        zong = $("<p>共0页 合计0条数据</p>")
                        $("#shu").append(zong)
                        m=$("<tr><td colspan=\"2\" id=\'b\'>还没有消息</td><td></td></tr>")
                        $("#massage").append(m);
                    }
                }
            })
        }
        function f() {
            if(count>0) {
                page = 1;
                page1 = (page - 1) * 12
                $("#massage").empty();
                lianjie(page1)
                $("#page1").css("background-color", "yellow")
                $("#page2").css("background-color", "white")
                $("#page3").css("background-color", "white")
            }

        }
        function f1() {
            if (count>=2) {
                page = 2;
                page1 = (page - 1) * 12
                $("#massage").empty();
                lianjie(page1)
                $("#page2").css("background-color", "yellow")
                $("#page1").css("background-color", "white")
                $("#page3").css("background-color", "white")
            }
        }
        function f2() {
            if (count>=3) {
                page = 3;
                page1 = (page - 1) * 12
                $("#massage").empty();
                lianjie(page1)
                $("#page3").css("background-color", "yellow")
                $("#page1").css("background-color", "white")
                $("#page2").css("background-color", "white")
            }
        }
        function shouye() {
            f()
        }
        function lianjie(page1) {
            $.ajax({
                url:'getjoinname.do?userid='+userid+'&page='+page1,
                success: function (data) {//data服务器返回的数据
                    if (data.length != 0) {
                        if (data[0].role1 == "组织管理员") {
                            gid = data[0].gid
                            $.each(data, function (index, grouppeople) {
                                m = $("<tr><td id=\'b\'>" + grouppeople.stunumber + " " + grouppeople.realname + "请求加入组织</td>" +
                                    "<td id=\'b1\'><a href=\"javascript:void(0)\" onclick=\'commit(" + grouppeople.muserid + "," + grouppeople.cuserid + "," + gid + "," + page1 + ")\'>同意</a>" +
                                    "<a href=\"javascript:void(0)\" id=\"no\" onclick=\'nocommit(" + grouppeople.muserid + "," + grouppeople.cuserid + "," + page1 + ")\'>不同意</a></td></tr>")
                                $("#massage").append(m);
                            })
                        }
                        else {
                            gid = data[0].gid
                            $.each(data, function (index, grouppeople) {
                                m = $("<tr><td id=\'b\'>" + grouppeople.gname + grouppeople.decide + "你加入组织</td>" +
                                    "<td id=\'b2\'><a href=\"javascript:void(0)\" onclick=\'commit1(" + grouppeople.muserid + "," + grouppeople.cuserid + "," + page1 + ")\'>收到</a>" +
                                    "</td></tr>")
                                $("#massage").append(m);
                            })
                        }
                    }
                    else {
                        m = $("<tr><td colspan=\"2\" id=\'b\'>还没有收到消息</td></tr>")
                        $("#massage").append(m);
                    }
                }
            });

        }
        function lastpage() {
            if (page > 0) {
                page = page - 1
                if (page == 1) {
                    f()
                } else if (page == 2) {
                    f1()
                } else if (page == 3) {
                    f2()
                } else if (page > 0) {
                    page1 = (page - 1) * 12
                    $("#page2").css("background-color", "white")
                    $("#page1").css("background-color", "white")
                    $("#page3").css("background-color", "white")
                    if (page > 0) {
                        $("#massage").empty();
                        lianjie(page1)
                    }
                }
            }
        }
        function nextpage() {
            if (page < count) {
                page = page + 1
                if (page == 1) {
                    f()
                } else if (page == 2) {
                    f1()
                } else if (page == 3) {
                    f2()
                } else if (page <= count) {
                    page = 4;
                    $("#page2").css("background-color", "white")
                    $("#page1").css("background-color", "white")
                    $("#page3").css("background-color", "white")
                    page1 = (page - 1) * 12
                    $("#massage").empty();
                    lianjie(page1)
                }

            }
        }
        function tiaozhuang() {
            var p = $("#tiao").val()
            if (p <= count && p > 0) {
                console.log(p)
                if (p == 1) {
                    f()
                } else if (p == 2) {
                    f1()
                } else if (p == 3) {
                    f2()
                } else if (p <= count) {
                    $("#page2").css("background-color", "white")
                    $("#page1").css("background-color", "white")
                    $("#page3").css("background-color", "white")
                    $("#tiao").val("")
                    page1 = (page - 1) * 12
                    $("#massage").empty();
                    lianjie(page1)
                }

            }
        }
        function weiye() {
            if (page==1){
                f()
            }
            if (page==2){
                f1()
            }
            if (page==3){
                f2()
            }
            if (page>3){
                $("#page2").css("background-color","white")
                $("#page1").css("background-color","white")
                $("#page3").css("background-color","white")
                page1=(page-1)*12
                $("#massage").empty();
                lianjie(page1)
            }

        }
    </script>
</head>
<body>
<div class="bei">
<div class="zong">
    <div class="main">
        <table>
            <thead>
            <tr><td id="b"><h3>消息内容</h3></td><td><h3>操作</h3></td></tr>
            </thead>
            <tbody id="massage">
            </tbody>
        </table>
    </div>
    <div class="page">
        <div class="g">
            <span><a href="javascript:void(0)" onclick="shouye()">首页</a></span>
            <span><a href="javascript:void(0)" onclick="lastpage()">上一页</a></span>
            <ul>
                <li id="page1" onclick="f()"><a href="javascript:void(0)">1</a></li>
                <li id="page2" onclick="f1()"><a href="javascript:void(0)" >2</a></li>
                <li id="page3" onclick="f2()"><a href="javascript:void(0)" >3</a></li>
            </ul>
            <span><a href="javascript:void(0)" onclick="nextpage()">下一页</a></span>
            <span><a href="javascript:void(0)" onclick="weiye()">尾页</a></span>
            <form>
                <input type="text" id="tiao">
                <input type="button" value="跳转" id="tiaobutton" onclick="tiaozhuang()">
            </form>
            <p id="shu"></p>
        </div>
    </div>
</div>
</div>
</body>
</html>